<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="title">
            <h2><a href="#" class="back" onclick="history.go(-1)"/>Visualizar Protocolo</h2>
        </ui:define>

        <ui:define name="body"> 
            <script  type="text/javascript" src="media/js/autoNumeric.js"></script>

            <p:panel styleClass="container_24 clearfix">
                <div class="buttonAction" style="float: right">
                    <p:button value="Editar" icon="ui-icon-pencil"
                              href="editarprotocolo.xhtml?eProtocolo=#{managerPesquisarProtocolo.protocoloVisualizar.id}"
                              styleClass="ui-priority-primary" />
                </div>
            </p:panel>

            <h:form id="protocoloForm" enctype="multipart/form-data">            
                <p:messages id="messages" closable="true" showDetail="true" autoUpdate="true"  />

                <div class="clear" />

                <p:panel id="protocoloPanel" styleClass="container_24 clearfix" >
                    <p:outputLabel value="Numero:" styleClass="grid_3" for="numeroInputText" />
                    <p:inputText id="numeroInputText" styleClass="grid_8" readonly="true"
                                 value="#{managerPesquisarProtocolo.numeroProtocolo()}" />

                    <p:outputLabel value="Data:" styleClass="grid_3" for="dataInputText" />
                    <p:inputText id="dataInputText" styleClass="grid_9" readonly="true"
                                 value="#{managerPesquisarProtocolo.protocoloVisualizar.dataProtocolo}">
                        <f:convertDateTime pattern="dd/MM/yyyy"/>
                    </p:inputText>
                    <div class="clear"/>
                    <br/>
                </p:panel>

                <h2>Credor</h2>
                <p:panel id="clientePanel" styleClass="container_24 clearfix">
                    <p:outputLabel value="#{managerPesquisarProtocolo.pessoaFisica ? 'CPF:' : 'CNPJ:'}" 
                                   styleClass="grid_3"/>
                    <p:inputMask value="#{managerPesquisarProtocolo.pessoaFisica ? managerPesquisarProtocolo.clienteVisualizar.cpf : managerPesquisarProtocolo.clienteVisualizar.cnpj}" 
                                 styleClass="grid_8" mask="#{managerPesquisarProtocolo.pessoaFisica ? '999.999.999-99' : '99.999.999/9999-99' }"
                                 autocomplete="false" readonly="true" />
                    <div class="clear" />

                    <p:outputLabel value="#{managerPesquisarProtocolo.pessoaFisica ? 'Nome:' : 'Nome Fantasia:'}" 
                                   styleClass="grid_3 #{managerPesquisarProtocolo.pessoaFisica ? '' : 'nomeFantasiaLabel'}" 
                                   for="nomeInputText"/>
                    <p:inputText id="nomeInputText" readonly="true"
                                 value="#{managerPesquisarProtocolo.pessoaFisica ? managerPesquisarProtocolo.clienteVisualizar.nome : managerPesquisarProtocolo.clienteVisualizar.nomeFantasia}" 
                                 styleClass="grid_20"/>
                    <div class="clear" />

                    <p:outputLabel value="Nome da Mãe:" styleClass="grid_3" 
                                   for="nomeMaeInputText" rendered="#{managerPesquisarProtocolo.pessoaFisica}"/>
                    <p:inputText id="nomeMaeInputText" 
                                 value="#{managerPesquisarProtocolo.clienteVisualizar.nomeMae}" 
                                 readonly="true" rendered="#{managerPesquisarProtocolo.pessoaFisica}"
                                 styleClass="grid_20" />
                    <div class="#{managerPesquisarProtocolo.pessoaFisica ? 'clear' : ''}" />

                    <p:outputLabel value="RG:" styleClass="grid_3" 
                                   rendered="#{managerPesquisarProtocolo.pessoaFisica}"/> 
                    <p:inputText styleClass="grid_8" value="#{managerPesquisarProtocolo.clienteVisualizar.rg}" 
                                 readonly="true" rendered="#{managerPesquisarProtocolo.pessoaFisica}"/>

                    <p:outputLabel value="Data Nasc.:" styleClass="grid_3" 
                                   for="dataNascCalendar" rendered="#{managerPesquisarProtocolo.pessoaFisica}"/>
                    <p:inputText id="dataNascCalendar" styleClass="grid_9"
                                 value="#{managerPesquisarProtocolo.clienteVisualizar.dataNascimento}"
                                 readonly="true" rendered="#{managerPesquisarProtocolo.pessoaFisica}" >
                        <f:convertDateTime pattern="dd/MM/yyyy"/>
                    </p:inputText>
                </p:panel>

                <p:panel id="processosPanel" styleClass="container_24 clearfix">

                    <h2>Processos</h2>
                    <br/>
                    <p:commandButton value="Versão Completa" icon="ui-icon-print"
                                     ajax="false"  update="@form" process="@form" 
                                     onclick="this.form.target='_blank'" style="margin-bottom: 10px;"
                                     styleClass="right" actionListener="#{managerPesquisarProtocolo.visualizarDocs()}"/>
                    <div class="clear"/>
                    <p:dataTable id="processosListTable" var="item" value="#{managerPesquisarProtocolo.processosVisualizar}" 
                                 styleClass="grid_24" emptyMessage="Nenhum registro">  
                        <f:facet name="header">
                            Processos
                        </f:facet>

                        <p:column headerText="Nome" style="vertical-align: middle">
                            #{item.tipoProcesso.nome}
                        </p:column>

                        <p:column headerText="Data" width="130" style="text-align: center; vertical-align: middle">  
                            <h:outputLabel value="#{item.dataProcesso}">
                                <f:convertDateTime pattern="dd/MM/yyyy"/>
                            </h:outputLabel>
                        </p:column> 

                        <p:column headerText="Anexos" style="text-align: center;">  
                            <ui:repeat value="#{item.anexos}" var="a" >
                                <p:panel styleClass="grid_5" >
                                    <h:outputLink value="#{a.tipo ne 'application/pdf' ? 'viewImage.xhtml':'show'}" 
                                                  title="#{a.tipo}"  target="_blank" style="text-align: center">

                                        <div id="divLink" class="grid_4">

                                            <p:graphicImage styleClass="image grid_3" 
                                                            rendered="#{a.tipo ne 'application/pdf'}"
                                                            style="margin-left:1%; width: 40px;"
                                                            url="show/?annex=#{a.url.concat('thumbnail.').concat(a.nome)}" />
                                            <p:graphicImage styleClass="image grid_3" 
                                                            rendered="#{a.tipo eq 'application/pdf'}"
                                                            style="margin-left:1%; width: 40px;" 
                                                            url="assets/images/pdf.jpeg" />
                                            <div class="clear"/>

                                            <p:outputLabel value="#{managerPesquisarProtocolo.nomeAnexo(a)}" 
                                                           style="margin-left:-5px; width: 100px; font-size: 13px;" 
                                                           rendered="#{a.tipo ne 'application/pdf'}"/>
                                            <p:outputLabel  value="#{managerPesquisarProtocolo.nomeAnexoPdf(a)}" 
                                                            style="margin-left:-5px; width: 100px; font-size: 13px" 
                                                            rendered="#{a.tipo eq 'application/pdf'}"/>
                                        </div>
                                        <f:param name="annex" value="#{a.url.concat(a.nome)}"/>
                                    </h:outputLink>
                                </p:panel>
                            </ui:repeat>
                        </p:column> 

                    </p:dataTable>

                </p:panel>

                <div class="buttonAction" >
                    <p:button value="Voltar" icon="ui-icon-circle-arrow-w"
                              href="pesquisarprotocolo.xhtml"/>
                </div>
            </h:form>

        </ui:define>
    </ui:composition>
</html>


